-- This file is part of the Fantasy Grounds Open Foundation Ruleset project. 
-- For the latest information, see http://www.fantasygrounds.com/
--
-- Copyright 2008 SmiteWorks Ltd.
--
-- This file is provided under the Open Game License version 1.0a
-- Refer to the license.html file for the full license text
--
-- All producers of work derived from this material are advised to
-- familiarize themselves with the license, and to take special
-- care in providing the definition of Product Identity (as specified
-- by the OGL) in their products.
--
-- All material submitted to the Open Foundation Ruleset project must
-- contain this notice in a manner applicable to the source file type.


function onInit()
	ChatManager.registerDiceHandler("fullattack", handleDiceLanded);
end

function handleDiceLanded(draginfo)
	for i = 1, draginfo.getSlotCount() do
		draginfo.setSlot(i);

		if not ModifierStack.isEmpty() then
			local originalnumber = draginfo.getNumberData();
			local numstr = originalnumber;
			if originalnumber > 0 then
				numstr = "+" .. originalnumber;
			end
			
			draginfo.setStringData(draginfo.getStringData() .. " " .. numstr .. " (" .. ModifierStack.getDescription(true) .. ")");
			draginfo.setNumberData(draginfo.getNumberData() + ModifierStack.getSum());
		end

		local entry = {};
		entry.text = draginfo.getStringData();
		entry.font = "systemfont";
		entry.dice = draginfo.getDieList();
		entry.diemodifier = draginfo.getNumberData();
		
		if User.isHost() then
			if ChatManager.getDieRevealFlag() then
				entry.dicesecret = false;
			end
			entry.sender = GmIdentityManager.getCurrent();
		else
			entry.sender = User.getIdentityLabel();
		end
		
		ChatManager.deliverMessage(entry);
	end
	
	ModifierStack.reset();
	return true;
end